
/* 清除手机号数据 */
export function clearPhoneData(parameter: { mbl: string }) {
  return request.post({
    url: "/client/test/testUpdateUserInValidByMobile",
    data: {
      mbl: parameter.mbl,
      unm: "op_test",
      upd: "Awa8N_BYB7ad2@ad_!Rm"
    }
  })
}
// clearPhoneData({ mbl: "18368562648" })

/* 刷新数据配置 */
export function updateResourceConfig() {
  return request.post({ url: "/client/content/updateResourceConfig" })
}
// updateResourceConfig()

/* 清除数据 */
export function clearData() {
  return request.post({ url: "/client/user/dataCleanUp" })
}
// clearData()

import bannerurl from "@/assets/images/banner553x263.jpg"
import bannerurl2 from "@/assets/test.mp4"

async function fetchAndConvertToBlob(url: string) {
  const response = await fetch(url)
  const blob = await response.blob()
  return blob
}

export function uploadFileToUrl() {
  fetchAndConvertToBlob(bannerurl).then((blob) => {
    // 将 Blob 对象转换为 File 对象
    const file = new File([blob], "image1.jpeg", { type: "image/jpeg" })
    // const file = new File([blob], "v1.mp4", { type: "video/mp4" })
    return request.post({
      url: "/client/file/upload",
      data: {
        file: file
      },
      headers: {
        "Content-Type": "multipart/form-data"
      }
    })
  })
}
// uploadFileToUrl()

// 格式化excel表格数据
const excelFormatDate = (rows: any) => {
  let a = rows.slice(180)
  // console.log(a)
  let b = a.map((item: any) => {
    let l = item['更新数据'].replaceAll('\r\n', '')
    // 替换中文逗号为英文逗号
    l = l.replace(/，/g, ',')
    // 为键名添加双引号
    l = l.replace(/(\w+)(?=:)/g, '"$1"')
    l = `[${l}]`
    return {
      uid: item._id,
      list: l.includes('无') ? [] : JSON.parse(l)
    }
  })
}

// 补充道具数
export function addToolData() {
  const params = [
    {
      commandId: 4,
      param1: 90, //道具数1，3
      param2: 180, //数量
      param3: 110068930 //别人的uid
    },
    {
      commandId: 4,
      param1: 90, //道具数1，3
      param2: 180, //数量
      param3: 110069222 //别人的uid
    },
    {
      commandId: 4,
      param1: 90, //道具数1，3
      param2: 180, //数量
      param3: 110058778 //别人的uid
    }
  ]
  const promises: any = params.map((i: any) => {
    return new Promise((r) => {
      // request
      //   .post({
      //     url: "/client/v2/user/gmcommand",
      //     data: i
      //   })
      //   .then(() => {
      //     r(i)
      //   })
      // setTimeout(() => {
      //   console.log(i)
      //   r(i)
      // }, 1000)
    })
  })
  Promise.all(promises)
    .then((r) => {
      console.log("补发成功", r)
    })
    .catch((e) => {
      console.log("补发失败", e)
    })
}
// addToolData()

// 获取ipv4
const getipv4 = () => {
  fetch('https://ipinfo.io/ip')
    .then((response) => response.text())
    .then((ip) => {
      console.log('Your IP address is:', ip)
    })
    .catch((error) => {
      console.error('Error fetching IP address:', error)
    })
}

/* 本地上传图片 */
export function nftUpload() {
  const param = {
    objectId: "public/JiangSuMH/0/32949ef677f34e94a158aa1f00cc180d.jpeg",
    url: "https://metacity-business.eos-suzhou-4.cmecloud.cn/metacity-business/public/JiangSuMH/0/32949ef677f34e94a158aa1f00cc180d.jpeg"
  }
  return request.post({
    url: "/client/user/nftUpload",
    data: param,
    headers: {
      "Content-Type": "application/json"
    }
  })
}
// nftUpload()